package com.example.snackfood.controller;

import com.example.snackfood.entity.Carts;
import com.example.snackfood.services.IsnackFoodCartsService;
import com.example.snackfood.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.Update;
import org.springframework.web.bind.annotation.*;

/**
 * @program: snackFood
 * @description:
 * @author: lydms
 * @create: 2023-11-24 22:54
 **/

@RestController
@RequestMapping("/Carts")
public class SnackFoodCartsController {


    @Autowired
    private IsnackFoodCartsService isnackFoodCartsService;

    //增：Carts
    @PostMapping("/saveCarts")
    public R saveBook(@RequestBody Carts carts) {
        isnackFoodCartsService.saveCarts(carts);
        return R.success("购物车增加成功");
    }
    //删：
    @DeleteMapping("/deleteCarts/{id}")
    public R delete(@PathVariable Long id){
        isnackFoodCartsService.deleteCarts(id);
        return R.success("成功删除");
    }

    //改：
    @PutMapping("/updateCarts")
    public R update(@RequestBody Carts carts){
        isnackFoodCartsService.updateCarts(carts);
        return R.success(carts);
    }

    //查（条件查询）：
    @GetMapping("/getCarts")
    public Carts getCarts(@RequestBody Carts carts){return isnackFoodCartsService.getCarts(carts);}

}
